package com.example.amusic.screen

import android.content.pm.PackageManager
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.example.amusic.viewmodel.MainViewModel
import com.example.amusic.MyApp
import com.example.amusic.utils.LocalNavController
import com.example.amusic.utils.Screen
import com.example.amusic.viewmodel.PlayViewModel

@Composable
fun NavGraph(modifier: Modifier = Modifier, mainViewModel: MainViewModel,playViewModel: PlayViewModel) {
    val context = LocalContext.current
    val startDestination =
        when (ContextCompat.checkSelfPermission(context, MyApp.STORAGE_PERMISSION)) {
            PackageManager.PERMISSION_GRANTED -> Screen.MAIN.router
            else -> Screen.PERMISSION.router
        }

    NavHost(
        navController = LocalNavController.current,
        modifier = modifier,
        startDestination = startDestination,
        builder = {
            composable(route = Screen.PERMISSION.router) {
                AskPermissionScreen()
            }

            composable(route = Screen.MAIN.router) {
                MusicMain(mainViewModel = mainViewModel,playViewModel = playViewModel)
            }
            composable(route = Screen.PLAYPAGE.router) {
                PlayPageScreen()
            }
        }
    )

}